package com.hoongs.v1.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hoongs.v1.dto.RiderCountDto;
import com.hoongs.v1.entity.Rider;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface RiderMapper extends BaseMapper<Rider> {

    @Select("SELECT \n" +
            "\tt1.user_id, \n" +
            "\tt1.id AS rider_id, \n" +
            "\tt1.name AS rider_name,\n" +
            "\tt1.status,\n" +
            "\tt1.is_work,\n" +
            "\tt1.rate,\n" +
            "\tt1.sortcode,\n" +
            "\t(SELECT COUNT(*) FROM orders WHERE rider_id = t1.id) AS order_num\n" +
            "FROM rider t1 \n" +
            "WHERE t1.status = 1 AND t1.is_work = 1\n" +
            "ORDER BY \n" +
            "\torder_num ASC,\n" +
            "\trate DESC,\n" +
            "\tsortcode DESC")
    List<Map<String, Object>> selectOrderCount();
}
